/**
 * Copyright (c) 时间, Tal.Ben 袁东昊 (ydonghao2@gmail.com).
 *
 * 版权
 */
package com.talben.soudian.adapter;

import java.io.File;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.Html;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import butterknife.ButterKnife;
import butterknife.InjectView;

import com.koushikdutta.ion.Ion;
import com.talben.soudian.AppConfig;
import com.talben.soudian.AppContext;
import com.talben.soudian.R;
import com.talben.soudian.TDevice;
import com.talben.soudian.adapter.GiftAdapter.ViewHolder;
import com.talben.soudian.api.UrlConnect;
import com.talben.soudian.apkinstaller.ApkTaskManager;
import com.talben.soudian.bean.ApkDetail;
import com.talben.soudian.bean.Gift;
import com.talben.soudian.util.FileUtil;
import com.talben.soudian.util.StringUtils;


/**
 * @Title: ApkAdapter.java
 * @Package com.talben.soudian
 * @Description: TODO(添加描述)
 * @author Tal.Ben
 * @date 2015年5月31日 下午3:29:06
 * @version v1.0
 */
public class NewApkAdapter extends ListBaseAdapter<Gift> {

	public NewApkAdapter() {
		super();
	}

	@SuppressLint("InflateParams")
    @Override
    protected View getRealView(int position, View convertView, ViewGroup parent) {
		ViewHolder vh = null;
        if (convertView == null || convertView.getTag() == null) {
            convertView = getLayoutInflater(parent.getContext()).inflate(
                    R.layout.list_cell_new_apk, null);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }

        final Gift gift = mDatas.get(position);
        
        Ion.with(vh.mGiftLogo)
           .load(UrlConnect.HOST+gift.getGicon());
//        vh.mGiftLogo.setImageResource(R.drawable.logo);
        vh.mTvGiftName.setText(gift.getGiftname());
        String description = gift.getDescription();
        vh.mTvGiftInfo.setVisibility(View.GONE);
        if (description != null && !StringUtils.isEmpty(description)) {
            vh.mTvGiftInfo.setVisibility(View.VISIBLE);
            vh.mTvGiftInfo.setText(Html.fromHtml(description.trim()));
        }
//        vh.mTvGiftResidue.setText(gift.getResidue());
//        vh.mTvGiftScore.setText(gift.getScore());
        vh.mLyAward.setVisibility(View.GONE);
        return convertView;
    }

    static class ViewHolder {
    	@InjectView(R.id.iv_gift_logo)
        ImageView mGiftLogo;
        @InjectView(R.id.tv_gift_name)
        TextView mTvGiftName;
        @InjectView(R.id.tv_gift_info)
        TextView mTvGiftInfo;
        @InjectView(R.id.tv_gift_residue)
        TextView mTvGiftResidue;
        @InjectView(R.id.tv_gift_score)
        TextView mTvGiftScore;
        @InjectView(R.id.ll_award)
        LinearLayout  mLyAward;

        public ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
	
}

